package com.bss.model;

import java.util.ArrayList;
import java.util.Date;
import java.util.List;

import javax.persistence.CascadeType;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.OneToMany;
import javax.persistence.Table;
import javax.persistence.Temporal;
import javax.persistence.TemporalType;
import javax.validation.constraints.NotNull;

/**
 * Admission generated by hbm2java
 */
@Entity
@Table(name = "admission")
public class Admission extends Payable {

	private static final long serialVersionUID = -4481623719583016079L;

	private Patient patient = new Patient();

	private Date dateOfAdmission = new Date();

	private Date dateOfExit;

	private Date dateFrom = new Date();

	private Date dateTo = new Date();

	private boolean exitInited;

	private boolean active;

	private String caseNo;

	private MedicalProblem medicalProblem = new MedicalProblem();

	private List<RoomBooking> roomBookings = new ArrayList<RoomBooking>(0);

	private List<BedBooking> bedBookings = new ArrayList<BedBooking>(0);

	private List<CurrentAttendent> currentAttendents = new ArrayList<CurrentAttendent>(0);

	private MaterialSet materialSet = new MaterialSet();

	private List<MaterialAllocation> materialAllocations = new ArrayList<MaterialAllocation>(0);

	public boolean isExitInited() {
		return this.exitInited;
	}

	public void setExitInited(final boolean exitInited) {
		this.exitInited = exitInited;
	}

	@ManyToOne(fetch = FetchType.EAGER)
	@JoinColumn(name = "idPatient")
	public Patient getPatient() {
		return this.patient;
	}

	public void setPatient(final Patient patient) {
		this.patient = patient;
	}

	@Temporal(TemporalType.TIMESTAMP)
	@Column(name = "dateOfAdmission", length = 19)
	public Date getDateOfAdmission() {
		return this.dateOfAdmission;
	}

	public void setDateOfAdmission(final Date dateofadmission) {
		this.dateOfAdmission = dateofadmission;
	}

	@Temporal(TemporalType.DATE)
	@Column(name = "dateFrom", length = 19)
	public Date getDateFrom() {
		return this.dateFrom;
	}

	public void setDateFrom(final Date dateFrom) {
		this.dateFrom = dateFrom;
	}

	@NotNull(message = "{admission.dateTo.NotNull}")
	@Temporal(TemporalType.DATE)
	@Column(name = "dateTo", length = 19)
	public Date getDateTo() {
		return this.dateTo;
	}

	public void setDateTo(final Date dateTo) {
		this.dateTo = dateTo;
	}

	// @NotNull(message = "{admission.caseNo.NotNull}")
	// @Size(min = 1, max = 10, message = "{admission.caseNo.Size}")
	@Column(name = "caseno", length = 10)
	public String getCaseNo() {
		return this.caseNo;
	}

	public void setCaseNo(final String caseno) {
		this.caseNo = caseno;
	}

	// @NotNull(message = "{admission.medicalProblem.NotNull}")
	@ManyToOne(fetch = FetchType.EAGER)
	@JoinColumn(name = "idmedicalProblem")
	public MedicalProblem getMedicalProblem() {
		return this.medicalProblem;
	}

	public void setMedicalProblem(final MedicalProblem medicalProblem) {
		this.medicalProblem = medicalProblem;
	}

	@OneToMany(fetch = FetchType.LAZY, mappedBy = "admission", cascade = CascadeType.PERSIST)
	public List<RoomBooking> getRoomBookings() {
		return this.roomBookings;
	}

	public void setRoomBookings(final List<RoomBooking> roomBookings) {
		this.roomBookings = roomBookings;
	}

	@OneToMany(fetch = FetchType.LAZY, mappedBy = "admission")
	public List<CurrentAttendent> getCurrentAttendents() {
		return this.currentAttendents;
	}

	public void setCurrentAttendents(final List<CurrentAttendent> currentattendents) {
		this.currentAttendents = currentattendents;
	}

	@OneToMany(fetch = FetchType.LAZY, mappedBy = "admission", cascade = CascadeType.PERSIST)
	public List<MaterialAllocation> getMaterialAllocations() {
		return this.materialAllocations;
	}

	public void setMaterialAllocations(final List<MaterialAllocation> materialallocations) {
		this.materialAllocations = materialallocations;
	}

	public void setMaterialSet(final MaterialSet materialSet) {
		this.materialSet = materialSet;
	}

	@ManyToOne(fetch = FetchType.EAGER)
	@JoinColumn(name = "idMaterialSet")
	public MaterialSet getMaterialSet() {
		return this.materialSet;
	}

	public void setBedBookings(final List<BedBooking> bedBookings) {
		this.bedBookings = bedBookings;
	}

	@OneToMany(fetch = FetchType.LAZY, mappedBy = "admission", cascade = CascadeType.PERSIST)
	public List<BedBooking> getBedBookings() {
		return this.bedBookings;
	}

	@Temporal(TemporalType.TIMESTAMP)
	@Column(name = "dateOfExit", length = 19)
	public Date getDateOfExit() {
		return this.dateOfExit;
	}

	public void setDateOfExit(final Date dateOfExit) {
		this.dateOfExit = dateOfExit;
	}

	@Override
	public String toString() {
		return this.getPatient() + ", Case: " + this.getCaseNo();
	}

	public void setActive(final boolean active) {
		this.active = active;
	}

	public boolean isActive() {
		return this.active;
	}

}
